export default function ({app}) {
  app.$axios.defaults.baseURL = 'https://cnodejs.org/api/v1';
  let userInfo  = app.$cookies.get('userInfo');
  app.$axios.interceptors.request.use(config=>{
    //在请求对象中加token
    if(userInfo&&userInfo.accesstoken&&config.method == 'post'){
      config.data.accesstoken = userInfo.accesstoken;
    }
    return config
  },error => {

  })
  app.$axios.interceptors.response.use(res=>{
    return  new Promise((resolve, reject)=>{
      if(res.data.success){
        resolve(res.data)
      }else {
        reject(res)
      }
    })

  },error=>{
    return error
  })
}
